<?php
	
	#
	# Garlic PHP/0.10
	# Copyleft (C) 2010 By Philip Patrick Butkiewicz (Bagno/Yuuki) and others (see "AUTHORS")
	# Project website: http://code.google.com/p/garlic-php
	#
	
	class garlicHttp {
		
		private $_curl;
		
		public function httpPost((string)$url, (string)$fields, (string)$cookie = "cookie.txt", $opt = array()) {
			$this->_curl = curl_init($url);
			
			if (file_exists($cookie)) {
				curl_setopt($this->_curl, CURLOPT_COOKIEFILE, $cookie);
			}
			curl_setopt($this->_curl, CURLOPT_VERBOSE, 0);
			curl_setopt($this->_curl, CURLOPT_COOKIEJAR, $cookie);
			curl_setopt($this->_curl, CURLOPT_POST, 1);
			curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $fields);
			curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($this->_curl, CURLOPT_FOLLOWLOCATION, 1);
			
			foreach ($opt as $_opt) {
				curl_setopt($this->_curl, $_opt, $_opt[$_opt]);
			}
			
			return curl_exec($this->_curl);
			curl_close($this->_curl);
		}
		
		public function httpGet((string)$url, (string)$cookie = "cookie.txt", $opt = array()) {
			$this->_curl = curl_init($url);
			
			if (file_exists($cookie)) {
				curl_setopt($this->_curl, CURLOPT_COOKIEFILE, $cookie);
			}
			
			curl_setopt($this->_curl, CURLOPT_COOKIEJAR, $cookie);
			curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($this->_curl, CURLOPT_FOLLOWLOCATION, 1);
			
			foreach ($opt as $_opt) {
				curl_setopt($this->_curl, $_opt, $_opt[$_opt]);
			}
			
			return curl_exec($this->_curl);
			curl_close($this->_curl);
		}
	}
?>
